{extend name="common@create" /}
{block name="mycss"}
{css href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.css" /}
{/block}
{block name="formaa"}
	<div class="form form-horizontal text-c">
		<img id='rypic' width="400px" src="__UPLOAD__/jiaoshirongyu/{$list.pic}">
	</div>
	<form action="/jsryinfo/{$list.id}" method="PUT" class="form form-horizontal" id="form-member-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">荣誉标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$list.title}" placeholder="荣誉标题" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">荣誉编号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$list.bianhao}" placeholder="荣誉编号" id="bianhao" name="bianhao">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">获奖人：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text mb-10" value="" placeholder="参与人(姓名、首拼、全拼" id="hjteacher" name="hjteacher" style="max-width: 200px;min-width: 80px" onkeyup="hjSelect(this)">
				<div id="addHj">
					{volist name="list.hj_jsry" id="vo"}
					<span>
						<input type="hidden" value="{$vo.teacherid}" name="hjteachers[]">
						<input class="btn btn-success radius mr-5 size-MINI" type="button" value="{$vo.teacher.xingming}" onclick="delCy(this)">
					</span>
					{/volist}
				</div>
				<div id="hjSelect"></div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">参与人：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text mb-10" value="" placeholder="参与人(姓名、首拼、全拼" id="cyteacher" name="cyteacher" style="max-width: 200px;min-width: 80px" onkeyup="cySelect()">
				<div id="addCy">
					{volist name="list.cy_jsry" id="vo"}
					<span>
						<input type="hidden" value="{$vo.teacherid}" name="cyteachers[]">
						<input class="btn btn-success radius mr-5 size-MINI" type="button" value="{$vo.teacher.xingming}" onclick="delCy(this)">
					</span>
					{/volist}
				</div>
				<div id="cySelect"></div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>荣誉所在单位：</label>
			<div class="formControls col-xs-8 col-sm-9 f-l">
				<span class="select-box f-l" style="width:300px;">
				{php} $school = schlist('校级','区级');{/php}
				<select class="select" id="hjschool" name="hjschool" size="1" required>
					<option value="">--请选择获奖单位--</option>
					{volist name="school" id="vo"}
						<option value="{$vo.id}" {eq name="$list.hjschool" value="$vo['id']" }selected{/eq}>{$vo.title}</option>
					{/volist}
				</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>荣誉所属学科：</label>
			<div class="formControls col-xs-8 col-sm-9 f-l">
				<span class="select-box f-l" style="width:300px;">
				{php}
					$subject = new \app\teach\model\Subject;
					$sjlist = $subject->where('status',1)->field('id,title')->order(['paixu'])->select();
				{/php}
				<select class="select" id="subject" name="subject" size="1" required>
					<option value="">--请选择荣誉所属学科--</option>
					{volist name="sjlist" id="vo"}
						<option value="{$vo.id}" {eq name="$list.subject" value="$vo['id']" }selected{/eq}>{$vo.title}</option>
					{/volist}
				</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>奖项：</label>
			<div class="formControls col-xs-8 col-sm-9 f-l">
				<span class="select-box f-l" style="width:180px;">
				{php}$jiangxiang = getCategory(113);{/php}
				<select class="select" id="jiangxiang" name="jiangxiang" size="1" required>
					<option value="">--请选择奖项--</option>
					{volist name="jiangxiang" id="vo"}
						<option value="{$vo.id}" {eq name="$list.jiangxiang" value="$vo['id']" }selected{/eq}>{$vo.title}</option>
					{/volist}
				</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>获奖时间：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text Wdate" value="{if $list.hjshijian > 0 }{$list.hjshijian}{else /}{$list.ry_tuce.fzshijian}{/if}" placeholder="" id="hjshijian" name="hjshijian" onclick="WdatePicker({isShowClear:false,readOnly:false})" style="width: 180px">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
{/block}
{block name="yanzheng"}
{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.js"}
<script type="text/javascript">

	// 上传文件
	$(function(){
	    $('.skin-minimal input').iCheck({
	        checkboxClass: 'icheckbox-blue',
	        radioClass: 'iradio-blue',
	        increaseArea: '20%'
	    });
	    
	    $list = $("#fileList"),
	    $btn = $("#btn-star"),
	    state = "pending",
	    uploader;

	    var uploader = WebUploader.create({
	        auto: false,
	        swf: '/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/Uploader.swf',
	    
	        // 文件接收服务端。
	        server: '{:url("upload")}',
	     
	        // 选择文件的按钮。可选。
	        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
	        pick: '#filePicker',
	    
	        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
	        resize: false,
	        //上传时提交自身需要的字段并传递到后台。
	        formData: {
	        	rongyuce : $('#rongyuce').val(),
	        }, 
	        // 只允许选择图片文件。
	        accept: {
	            title: 'Images',
	            extensions: 'gif,jpg,jpeg,bmp,png',
	            // mimeTypes: 'application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel'
	            mimeTypes: 'image/*'
	        },

	        fileNumLimit: 1, // 上传文件数
	        fileSizeLimit:2*1024*1024,
	    });
	    uploader.on( 'fileQueued', function( file ) {
	        var $li = $(
	            '<div id="' + file.id + '" class="item">' +
	                '<div class="pic-box"><img></div>'+
	                '<div class="info">' + file.name + '</div>' +
	                '<p class="state">等待上传...</p>'+
	            '</div>'
	        ),
	        $img = $li.find('img');
	        $list.append( $li );
	    
	        // 创建缩略图
	        // 如果为非图片文件，可以不用调用此方法。
	        // thumbnailWidth x thumbnailHeight 为 100 x 100
	        uploader.makeThumb( file, function( error, src ) {
	            if ( error ) {
	                $img.replaceWith('<span>不能预览</span>');
	                return;
	            }
	    
	            $img.attr( 'src', src );
	        }, thumbnailWidth, thumbnailHeight );
	    });
	    // 文件上传过程中创建进度条实时显示。
	    uploader.on( 'uploadProgress', function( file, percentage ) {
	        var $li = $( '#'+file.id ),
	        $percent = $li.find('.progress-box .sr-only');
	    
	        // 避免重复创建
	        if ( !$percent.length ) {
	            $percent = $('<div class="progress-box"><span class="progress-bar radius"><span class="sr-only" style="width:0%"></span></span></div>').appendTo( $li ).find('.sr-only');
	        }
	        $li.find(".state").text("上传中");
	        $percent.css( 'width', percentage * 100 + '%' );
	    });
	    
	    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
	    uploader.on( 'uploadSuccess', function( file ) {
	        $( '#'+file.id ).addClass('upload-state-success').find(".state").text("已上传");
	    });
	    
	    uploader.on( 'uploadAccept', function( file, response ) {
	        $('#pic').val(response.url);
	        $('#id').val(response.ryid);
	        $('#form-member-add').attr('action','/jsryinfo/'+response.ryid);
	    });

	    // 文件上传失败，显示上传出错。
	    uploader.on( 'uploadError', function( file ) {
	        $( '#'+file.id ).addClass('upload-state-error').find(".state").text("上传出错");
	    });
	    
	    // 完成上传完了，成功或者失败，先删除进度条。
	    uploader.on( 'uploadComplete', function( file ) {
	        $( '#'+file.id ).find('.progress-box').fadeOut();
	    });
	    uploader.on('all', function (type) {
	        if (type === 'startUpload') {
	            state = 'uploading';
	        } else if (type === 'stopUpload') {
	            state = 'paused';
	        } else if (type === 'uploadFinished') {
	            state = 'done';
	        }

	        if (state === 'uploading') {
	            $btn.text('暂停上传');
	        } else {
	            $btn.text('开始上传');
	        }
	    });

	    $btn.on('click', function () {
	        if (state === 'uploading') {
	            uploader.stop();
	        } else {
	            uploader.upload();
	        }
	    });

	});


	// 获取获奖教师列表
	function hjSelect(obj)
	{
		$('#hjSelect').empty();
		$('#cySelect').empty();
		var str = "";
		str = $('#hjteacher').val();
		if(str.length<=0)
		{
			return "";
		}
		$.post(
			"{:Url::build('renshi/index/srcTeacher')}",
			{
				"str":str,
			},
			function(data,status){
				$('#hjSelect').empty();
				$('#cySelect').empty();
				if($.isEmptyObject(data))
				{
					return true;
				}
				for (var i = data.length - 1; i >= 0; i--) {
					var myhtml = "";
					myhtml = "<input class='btn btn-secondary radius mr-5 size-MINI' type='button' value='" + data[i]['xingming'] + "' onclick=addHj(this,"+data[i]['id']+") title="+data[i]['js_danwei']['jiancheng']+'　'+data[i]['sex']+'　'+data[i]['age']+" >";
					$('#hjSelect').append(myhtml);
				}
				
			}
		);
	}

	// 添加参与人
	function addHj(obj,teacherId)
	{
		$('#hjteacher').val('');
		$('#cyteacher').val('');
		$(obj).attr('class','btn btn-warning radius mr-5 size-MINI');
		$(obj).attr('onclick','delCy(this)');
		var myhtml = "";
		myhtml = "<span><input type='hidden' name='hjteachers[]' value ="+teacherId+"></span>";
		$('#addHj').append(myhtml);
		$('#addHj').children("span").last().append(obj);
	}


	// 获取参与教师列表
	function cySelect(obj)
	{
		$('#hjSelect').empty();
		$('#cySelect').empty();
		var str = "";
		str = $('#cyteacher').val();
		if(str.length<=0)
		{
			return "";
		}
		$.post(
			"{:Url::build('renshi/index/srcTeacher')}",
			{
				"str":str,
			},
			function(data,status){
				$('#hjSelect').empty();
				$('#cySelect').empty();
				if($.isEmptyObject(data))
				{
					return true;
				}
				for (var i = data.length - 1; i >= 0; i--) {
					var myhtml = "";
					myhtml = "<input class='btn btn-secondary radius mr-5 size-MINI' type='button' value='" + data[i]['xingming'] + "' onclick=addCy(this,"+data[i]['id']+") title="+data[i]['js_danwei']['jiancheng']+'　'+data[i]['sex']+'　'+data[i]['age']+" >";
					$('#cySelect').append(myhtml);
				}
				
			}
		);
	}


	// 添加参与人
	function addCy(obj,teacherId)
	{
		$('#hjteacher').val('');
		$('#cyteacher').val('');
		$(obj).attr('class','btn btn-warning radius mr-5 size-MINI');
		$(obj).attr('onclick','delCy(this)');
		var myhtml = "";
		myhtml = "<span><input type='hidden' name='cyteachers[]' value ="+teacherId+"></span>";
		$('#addCy').append(myhtml);
		$('#addCy').children("span").last().append(obj);
	}

	// 删除参与人
	function delCy(obj)
	{
		$(obj).parent().remove();
	}

	// 匹配用户名
	$.validator.addMethod("zh",function(value,element){
		var tel = /^[\u4e00-\u9fa5]*$/;
		return this.optional(element) || tel.test(value);
	}, "请输入中文");

	// 设置表单验证规则
	var myrules = {
			title:{
				maxlength:100,
			},
			hjshijian:{
				required:true,
				dateISO:true
			},
			bianhao:{
				maxlength:15,
			},
		};

	// 设置表单提交方式
	var mytype = 'PUT';

	
</script>
{/block}